package com.zzc.study.controller;

import cn.hutool.core.date.DateUtil;
import com.zzc.study.service.AiAssistant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class ChatLanguageModelController {
    @Autowired
    private AiAssistant aiAssistant;

    //http://localhost:9009/chatgraalvm/test1?prompt=8
    @GetMapping(value = "/chatgraalvm/test1")
    public String test1(@RequestParam("prompt") String prompt) {
        //斐波那契数列的定义：每一项都是前两项的和，除了最开始的两个指定数值外
        String code = String.format("""
        function fibonacci(n) {
            if (n <= 1) return n;
            return fibonacci(n - 1) + fibonacci(n - 2);
        }
                        
        fibonacci(%s)  // 动态替换这里的参数
        """, prompt);  // 使用请求参数 prompt 作为输入

        //String result = aiAssistant.chat("勾股定理有哪些组合");
        //String result = aiAssistant.chat("16开平方等于多少");
        String result = aiAssistant.chat(code);
        System.out.println(result);

        return  "success :" +  DateUtil.now() + "\t"+result;
    }
}
